from django.shortcuts import render
from rest_framework.response import Response
from rest_framework import status,viewsets
from .serializer import ColumnSerializer, ColumnDetailSerializer
from .models import Column
# Create your views here.

class ColumnViewSet(viewsets.ModelViewSet):
    serializer_class = ColumnSerializer

    def get_queryset(self):
        queryset = Column.objects.all()
        params = self.request.query_params
        if params:
            filters = {}
            for key, value in params.items():
                filters[key] = value
            queryset = queryset.filter(**filters)
        return queryset

class ColumnDetailViewSet(viewsets.ModelViewSet):
    serializer_class = ColumnDetailSerializer

    def get_queryset(self):
        queryset = Column.objects.all()
        params = self.request.query_params
        if params:
            filters = {}
            for key, value in params.items():
                filters[key] = value
            queryset = queryset.filter(**filters)
        return queryset
